package Interceptor;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import model.User;

/**
 * Created by Properly on 2018/7/3.
 */
public class AdminCheckInterceptor implements Interceptor {
    @Override
    public void intercept(Invocation invocation) {
        Controller controller = invocation.getController();

        //登录
        if (controller.getSessionAttr("user") != null) {
            User user = controller.getSessionAttr("user");
            String username = user.getUsername();

            if (username.equals("admin")){
                invocation.invoke();
            }else {
                controller.renderHtml("对不起，您没有该权限");
            }

        } else { //未登录则跳转到登录页面
            controller.redirect("/login");
        }


    }
}
